const db = wx.cloud.database()
let myaudio = wx.createInnerAudioContext({
  useWebAudioImplement: true
}),
openid = wx.getStorageSync('userInfo').openid,
wordName = {}


// pages/BookDetail/bookDetael.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    word:{},
  },

  async remove(e){
    await wx.cloud.callFunction({
        name: 'removeDictWord',
        data: {
            type: 'rvmnote',
            id: wordName._id
        }
    }).then(res => {
        wx.navigateBack()
    })
    

  },


  read(){
      myaudio.src = 'https://dict.youdao.com/dictvoice?audio='+wordName.content+'&type=2'
      myaudio.play();

  },

  audio: function(){
      if (wordName.address){
        wx.navigateTo({
            url: '/pages/wordBook/playerAudio/playerAudio?word=' + JSON.stringify(wordName),
          })
      }else{
          wx.showToast({
            title: '此单词没有音频',
            icon:'none'
          })
      }
      
  },


  back:function(){
    wx.navigateBack()
  },
  /**
   * 生命周期函数--监听页面加载
   */
  async onLoad(options) {
      let item = JSON.parse(options.item)
      console.log(item,item.content)
      let {result} = await wx.cloud.callFunction({
          name:'queryWord',
          data:{
              content:item.content
          }
      })
      console.log(result)
      wordName = result[0]
      wx.setStorageSync('bookDetail', wordName)
      this.setData({
        word: wordName,
    })
  },
})